/*********************************************************************\
*
*                  (c) lkc
*                  All Rights Reserved. lkc Confidential
*
\*********************************************************************/
/*********************************************************************\
*   Title                      :
*
*   Module Description         :
*
*   Author                     : lkc
*
*   Created                    : 2018-6-24
*
\*********************************************************************/
#ifndef PROTOCOLPOD_H
#define PROTOCOLPOD_H

#include "Communicate.h"
#ifdef POD_IS_205
#ifdef POD_COMM_TYPE_IS_QT
#include <QObject>
#include "ProtocolBaseQt.h"
class ProtocolPod205 : public QObject, public ProtocolBaseQt
{
    Q_OBJECT
#else
#include "ProtocolBasePosix.h"
class ProtocolPod205 : public ProtocolBasePosix
{
#endif//#ifdef POD_COMM_TYPE_IS_QT
public:
    static ProtocolPod205& GetInstance() {return m_Instance;}//获取实例
    ProtocolPod205& operator = (const ProtocolPod205&) = delete;
    ProtocolPod205(const ProtocolPod205&) = delete;
private:
    static ProtocolPod205 m_Instance;
    ProtocolPod205() {}
public:    
    void ExtractData(const unsigned char *data, int nLength) override;
    int CycleSendOnce() override;
private:
    void EventReceiveFrameParse();
//    int GetCycleTimeMS() override {return 40;}
    void SelfCheckParse();
    void GainParse();
    void FoucsParse();
    void ContrastParse();
    void OutModeParse();
    void WorkModeParse();
protected:
    int GetCycleTimeMS() override {return 40;}
private:
    const static int FRAME_LENGTH_RECEIVE = 7;
    const static unsigned char HEAD1 = 0xE0;
    const static unsigned char HEAD2_EVENT = 0x00;
    const static unsigned char END = 0xFB;
    const static int OBJECT_NUM_MAX = 10;
    const static unsigned char HEAD2_CYCLE = 0x01;
    const static unsigned char NORMAL_CYCLE = 0x00; //数据有效性 0x00 正常状态 0x01 异常状态
    const static unsigned char ABNORMAL_CYCLE = 0x01;//数据有效性 0x01 异常状态
    const static unsigned char RESULT_SUCCESS = 0x00;
    const static unsigned char RESULT_FAIL = 0x80;
    unsigned char m_funcCodeSend;
    unsigned char m_commandSend;
    unsigned char m_dataSend;
    unsigned char m_resultSend;
    unsigned char m_funcCodeReceive;
    unsigned char m_commandReceive;
    unsigned char m_dataReceive;
};

#endif //#ifdef POD_IS_205
#endif // PROTOCOLPOD_H

/********************************************************************\
 *
 * REVISION RECORDS
 *
\*********************************************************************/
/*********************************************************************/
/*
 *
 *
 *
\*********************************************************************/
/*------------------------------The End------------------------------*/
